window.onload = function () {
    //步骤一:创建异步对象
    var ajax = new XMLHttpRequest();
//步骤二:设置请求的url参数,参数一是请求的类型,参数二是请求的url,可以带参数,动态的传递参数starName到服务端
    ajax.open('get','http://localhost:8080/downFile');
// 设置返回值的类型
    ajax.responseType = 'blob';
//步骤三:发送请求
    ajax.send();
//步骤四:注册事件 onreadystatechange 状态改变就会调用
    xhr.onreadystatechange = function(){
        if (this.readyState == 4 && this.status == 200){
            //this.response is what you're looking for
            console.log(this.response, typeof this.response);
            let newUrl = URL.createObjectURL(this.response);
            let aElement = document.createElement("a");
            aElement.href = newUrl;
            aElement.download = '新文件';
            document.body.appendChild(aElement);
            aElement.click();
            document.body.removeChild(aElement);
            URL.revokeObjectURL(newUrl);
        }
    }
}